package com.zeny.edu.eduservice.controller;


import com.zeny.edu.common.ResponseResult;
import com.zeny.edu.eduservice.entity.EduVideo;
import com.zeny.edu.eduservice.service.EduVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author zeny
 * @since 2020-03-05
 */
@RestController
@RequestMapping("/eduservice/video")
@CrossOrigin
public class EduVideoController {

    @Autowired
    private EduVideoService eduVideoService;

    /**
     * @Description 添加小节
     * @Date 2020/3/5 0005 22:14
     * @param eduVideo
     * @return com.zeny.edu.common.ResponseResult
     **/
    @PostMapping("/addVideo")
    public ResponseResult addVideo(@RequestBody EduVideo eduVideo) {
        boolean success = eduVideoService.save(eduVideo);
        return success ? ResponseResult.ok() : ResponseResult.fail();
    }

    /**
     * @Description 查询小节
     * @Date 2020/3/5 0005 22:40
     * @param videoId
     * @return com.zeny.edu.common.ResponseResult
     **/
    @GetMapping("/getVedioInfo/{videoId}")
    public ResponseResult getVedioInfo(@PathVariable String videoId) {
        EduVideo eduVideo = eduVideoService.getById(videoId);
        return ResponseResult.ok().data("video", eduVideo);
    }

    /**
     * @Description 删除小节
     * @Date 2020/3/5 0005 22:42
     * @param videoId
     * @return com.zeny.edu.common.ResponseResult
     **/
    @DeleteMapping("/deleteVideo/{videoId}")
    public ResponseResult deleteVideo(@PathVariable String videoId) {
        boolean success = eduVideoService.removeVideo(videoId);
        return success ? ResponseResult.ok() : ResponseResult.fail();
    }

    /**
     * @Description 修改
     * @Date 2020/3/5 0005 22:44
     * @param eduVideo
     * @return com.zeny.edu.common.ResponseResult
     **/
    @PutMapping("/updateVideo")
    public ResponseResult updateVideo(@RequestBody EduVideo eduVideo) {
        boolean success = eduVideoService.updateById(eduVideo);
        return success ? ResponseResult.ok() : ResponseResult.fail();
    }
}

